import { createStore ,combineReducers} from 'redux'



//Books的reducer 


const BooksReducer = (state = { msg: 'books' }, action) => {
   console.log(action)

    switch (action.type) {

        case "ADD":
            return {
                msg:state.msg+'我给改变了'
            }


        default:
            return state

          
    }
}





//News的reducer  


const NewsReducer = (state = { msg: 'News' }, action) => {
    console.log(action)


    switch (action.type) {
        case "ADD":
            // return state.msg + '我是加的 NewsReducer '

            return {
                msg:state.msg+'我是加的 NewsReducer'
            }



        default:
            return state

          
    }
}





//List 的 reducer 


const ListReducer = (state = { msg: 'List' }, action) => {


    switch (action.type) {
        case "ADD":
            // return state.msg + '我是加的 ListReducer ' //错误的写法 需要返回一个对象

            return {
                msg:state.msg+'我是加的 ListReducer'
            }
            


        default:
            return state

        
    }
}










// const store = createStore(多个reducer的返回对象)

let  ManyReducers=combineReducers({
    BooksReducer,
    NewsReducer,
    ListReducer:ListReducer

})

const store = createStore(ManyReducers)
export default store